convert mapfactor to Format class (#843)
authortsteven4 <13596209+tsteven4@users.noreply.github.com>
Sat, 29 Jan 2022 21:09:48 +0000 (14:09 -0700)
committerGitHub <noreply@github.com>
Sat, 29 Jan 2022 21:09:48 +0000 (14:09 -0700)
* convert mapfactor to Format class.

* const memb funcs.

CMakeLists.txt
GPSBabel.pro
mapfactor.cc
mapfactor.h [new file with mode: 0644]
vecs.h

index cb48a65fe50d99011619b404d9afcb320855c900..616d385e3ceb5d055fee3c65c76917bd400d1196 100644 (file)
@@ -249,6 +249,7 @@ set(HEADERS
   legacyformat.h
   lowranceusr.h
   magellan.h
+  mapfactor.h
   mynav.h
   navilink.h
   nmea.h
index 9957d9f4fa9ea8609026caa4101d628ca269e580..6a1ada81e1555af562edc7f3e11a0ef8e3d15bdb 100644 (file)
@@ -236,6 +236,7 @@ HEADERS =  \
   legacyformat.h \
   lowranceusr.h \
   magellan.h \
+  mapfactor.h \
   mynav.h \
   navilink.h \
   nmea.h \
index 6aaf062264ea268f9c1b6200c52e1e0bd6fd1d48..28710d0c2bbf331a34fe3ad96e05a0cbdf75cced 100644 (file)
     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
  */
-#include "defs.h"
-#include "src/core/file.h"
-#include "src/core/xmlstreamwriter.h"
-#include <QDebug>
-#include <QXmlStreamReader>
-#include <QXmlStreamWriter>
+#include "mapfactor.h"
 
-static gpsbabel::File* oqfile;
-static QXmlStreamWriter* writer;
+#include <QByteArray>                  // for QByteArray
+#include <QIODevice>                   // for QIODevice, operator|, QIODevice::ReadOnly, QIODevice::Text, QIODevice::WriteOnly
+#include <QtGlobal>                    // for qPrintable
+#include <QStringLiteral>              // for QStringLiteral
+#include <QXmlStreamAttributes>        // for QXmlStreamAttributes
+#include <QXmlStreamReader>            // for QXmlStreamReader, QXmlStreamReader::EndElement, QXmlStreamReader::StartElement
+#include <QXmlStreamWriter>            // for QXmlStreamWriter
 
-static
-QVector<arglist_t> mapfactor_args = {
-};
+#include "defs.h"                      // for Waypoint, fatal, waypt_add, waypt_disp_all
+#include "src/core/file.h"             // for File
+#include "src/core/xmlstreamwriter.h"  // for XmlStreamWriter
 
-#define MYNAME "mapfactor"
-
-// This really should be class-local...
-static QXmlStreamReader reader;
-static QString mapfactor_read_fname;
-static  const double milliarcseconds = 60.0 * 60.0 * 1000.0;
 
-geocache_container wpt_container(const QString&);
+#define MYNAME "mapfactor"
 
-static void MapfactorRead()
+void MapfactorFormat::MapfactorRead()
 {
   Waypoint* wpt = nullptr;
 
@@ -66,14 +60,14 @@ static void MapfactorRead()
   }
 }
 
-static void
-mapfactor_rd_init(const QString& fname)
+void
+MapfactorFormat::rd_init(const QString& fname)
 {
   mapfactor_read_fname = fname;
 }
 
-static void
-mapfactor_read()
+void
+MapfactorFormat::read()
 {
   gpsbabel::File file(mapfactor_read_fname);
   file.open(QIODevice::ReadOnly);
@@ -89,14 +83,8 @@ mapfactor_read()
   }
 }
 
-
-static void
-mapfactor_rd_deinit()
-{
-}
-
-static void
-mapfactor_wr_init(const QString& fname)
+void
+MapfactorFormat::wr_init(const QString& fname)
 {
   oqfile = new gpsbabel::File(fname);
   oqfile->open(QIODevice::WriteOnly | QIODevice::Text);
@@ -107,8 +95,8 @@ mapfactor_wr_init(const QString& fname)
   writer->writeStartDocument();
 }
 
-static void
-mapfactor_wr_deinit()
+void
+MapfactorFormat::wr_deinit()
 {
   writer->writeEndDocument();
   delete writer;
@@ -118,8 +106,8 @@ mapfactor_wr_deinit()
   oqfile = nullptr;
 }
 
-static void
-mapfactor_waypt_pr(const Waypoint* waypointp)
+void
+MapfactorFormat::mapfactor_waypt_pr(const Waypoint* waypointp) const
 {
   writer->writeStartElement(QStringLiteral("item"));
 
@@ -129,30 +117,17 @@ mapfactor_waypt_pr(const Waypoint* waypointp)
   writer->writeEndElement();
 }
 
-static void
-mapfactor_write()
+void
+MapfactorFormat::write()
 {
   writer->writeStartElement(QStringLiteral("favourites"));
   writer->writeAttribute(QStringLiteral("version"), QStringLiteral("1"));
   // TODO: This could be moved to wr_init, but the pre GPX version put the two
   // lines above this, so mimic that behaviour exactly.
   writer->setAutoFormatting(true);
-  waypt_disp_all(mapfactor_waypt_pr);
+  auto mapfactor_waypt_pr_lambda = [this](const Waypoint* waypointp)->void {
+    mapfactor_waypt_pr(waypointp);
+  };
+  waypt_disp_all(mapfactor_waypt_pr_lambda);
   writer->writeEndElement();
 }
-
-ff_vecs_t mapfactor_vecs = {
-  ff_type_file,
-  { (ff_cap)(ff_cap_read | ff_cap_write), ff_cap_none, ff_cap_none },
-  mapfactor_rd_init,
-  mapfactor_wr_init,
-  mapfactor_rd_deinit,
-  mapfactor_wr_deinit,
-  mapfactor_read,
-  mapfactor_write,
-  nullptr,
-  &mapfactor_args,
-  CET_CHARSET_UTF8, 0  /* CET-REVIEW */
-  , NULL_POS_OPS,
-  nullptr
-};
diff --git a/mapfactor.h b/mapfactor.h
new file mode 100644 (file)
index 0000000..fad7f23
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+    Copyright (C) 2014 Robert Lipe
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+ */
+#ifndef MAPFACTOR_H_INCLUDED_
+#define MAPFACTOR_H_INCLUDED_
+
+#include <QString>           // for QString
+#include <QVector>           // for QVector
+#include <QXmlStreamReader>  // for QXmlStreamReader
+#include <QXmlStreamWriter>  // for QXmlStreamWriter
+
+#include "defs.h"            // for ff_cap, arglist_t, ff_cap_none, CET_CHARSET_UTF8, Waypoint, ff_cap_read, ff_cap_write, ff_type, ff_type_file
+#include "format.h"          // for Format
+#include "src/core/file.h"   // for File
+
+
+class MapfactorFormat : public Format
+{
+public:
+  QVector<arglist_t>* get_args() override
+  {
+    return &mapfactor_args;
+  }
+
+  ff_type get_type() const override
+  {
+    return ff_type_file;
+  }
+
+  QVector<ff_cap> get_cap() const override
+  {
+    /*                                  waypoints,      tracks,      routes */
+    return { (ff_cap)(ff_cap_read | ff_cap_write), ff_cap_none, ff_cap_none };
+  }
+
+  QString get_encode() const override
+  {
+    return CET_CHARSET_UTF8;
+  }
+
+  int get_fixed_encode() const override
+  {
+    return 0;
+  }
+
+  void rd_init(const QString& fname) override;
+  void read() override;
+  void wr_init(const QString& fname) override;
+  void write() override;
+  void wr_deinit() override;
+
+private:
+  /* Constants */
+
+  static constexpr double milliarcseconds = 60.0 * 60.0 * 1000.0;
+
+  /* Member Functions */
+
+  void MapfactorRead();
+  void mapfactor_waypt_pr(const Waypoint* waypointp) const;
+
+  /* Data Members */
+
+  gpsbabel::File* oqfile{};
+  QXmlStreamWriter* writer{};
+
+  QVector<arglist_t> mapfactor_args = {
+  };
+
+  QXmlStreamReader reader;
+  QString mapfactor_read_fname;
+};
+#endif // MAPFACTOR_H_INCLUDED_
diff --git a/vecs.h b/vecs.h
index 6afa0e04c30da7e34af7fcdcfd0c95f58510efd2..e82dc6b7f288e9e1186efd345fd12e5e1c2e0df1 100644 (file)
--- a/vecs.h
+++ b/vecs.h
@@ -42,6 +42,7 @@
 #include "kml.h"
 #include "legacyformat.h"
 #include "lowranceusr.h"
+#include "mapfactor.h"
 #include "mynav.h"
 #include "nmea.h"
 #include "osm.h"
@@ -126,7 +127,6 @@ extern ff_vecs_t enigma_vecs;
 extern ff_vecs_t format_garmin_xt_vecs;
 extern ff_vecs_t mapbar_track_vecs;
 extern ff_vecs_t f90g_track_vecs;
-extern ff_vecs_t mapfactor_vecs;
 #endif // MAXIMAL_ENABLED
 
 class Vecs
@@ -321,7 +321,7 @@ private:
   GarminFitFormat format_fit_fmt;
   LegacyFormat mapbar_track_fmt {mapbar_track_vecs};
   LegacyFormat f90g_track_fmt {f90g_track_vecs};
-  LegacyFormat mapfactor_fmt {mapfactor_vecs};
+  MapfactorFormat mapfactor_fmt;
   EnergymproFormat energympro_fmt;
   MyNavFormat mynav_fmt;
   GeoJsonFormat geojson_fmt;